<template>
  <div>
    <div class="class-view">
      <ul>
        <li>
          <div>
            <Icon type="ios-book-outline" class="class-icon"></Icon>
            <span class="class-name">课程统计</span>
          </div>
        </li>
        <li>
          <div>
            <Icon type="ios-cloud-upload-outline" class="class-icon"></Icon>
            <span class="class-name">上传资料</span>
          </div>
        </li>
        <li>
          <div>
            <Icon type="ios-bookmarks-outline" class="class-icon"></Icon>
            <span class="class-name">发布作业</span>
          </div>
        </li>
        <li>
          <div>
            <Icon type="ios-paper-outline" class="class-icon"></Icon>
            <span class="class-name">随堂练习</span>
          </div>
        </li>
      </ul>
    </div>

    <div class="class-table">
      <Card style="width:100%" dis-hover>
        <p slot="title">
          我教的课
        </p>
        <div slot="extra">
          <Form ref="formInline" inline>
            <FormItem label="学年学期" :label-width="80">
              <Select style="width: 180px">
                <Option value="1">2017-2018年第二学期</Option>
              </Select>
            </FormItem>
            <FormItem label="课程" :label-width="40">
              <Select style="width: 180px">
                <Option value="2">B18938|构造地质学</Option>
              </Select>
            </FormItem>
            <FormItem>
              <Button type="primary">查询</Button>
              <Button type="text" class="class-add">添加课程</Button>
            </FormItem>
          </Form>
        </div>

        <div class="class-sort">
          <div class="class-day">

            <ul>
              <li :style="{width: classDayWidth}" v-for="(item, idx) in classDay" :key="idx">{{item}}</li>
            </ul>
          </div>
          <div class="class-info">
            <div class="class-time">
              <div class="timer">
                <div>上午</div>
                <div>
                  <p>一</p>
                  <p>二</p>
                </div>
              </div>
              <div class="timer">
                <div>下午</div>
                <div>
                  <p>一</p>
                  <p>二</p>
                </div>
              </div>
              <div class="timer2">晚上</div>
            </div>

            <div class="info">
              <ul>
                <li v-for="x in classX" :style="{width: classDayWidth}" :key="x">
                  <div class="name" v-for="y in classY" :key="y">
                    <Tooltip :content="item.name" :key="index" placement="top" v-for="(item, index) in classInfo" v-if="item.x == x && item.y == y">
                      <span>{{item.name}}</span>
                    </Tooltip>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </div>

      </Card>
    </div>
  </div>
</template>
<script>
  export default {
    created() {

      let classInfo = [{
        x: 1,
        y: 1,
        name: '语文',
        id: 1
      }, {
        x: 5,
        y: 4,
        name: '语文',
        id: 2
      }, {
        x: 2,
        y: 3,
        name: '体育',
        id: 3
      }, {
        x: 4,
        y: 5,
        name: '历史',
        id: 4
      }]
      let x = [], y = []
      classInfo.forEach(item => x.push(item.x))
      //先找出X轴，星期轴的最大是周几
      x.sort((a, b) => b - a)

      const weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
      this.classDayWidth = (100 / parseInt(x[0])) + '%'

      for (let i = 0; i < x[0]; i++) {
        this.classDay.push(weekArr[i])
        this.classX.push(i + 1)
      }

      this.classInfo = classInfo
    },
    data() {
      return {
        classX: [],
        classY: [1, 2, 3, 4, 5],
        classDay: [],
        classInfo: [],
        classDayWidth: '0%'
      }
    }
  }
</script>
<style scoped>
  .class-view{
    height: 110px;
    padding: 20px 10px;
    background: #fff;
  }
  .class-view li{
    float: left;
    width: 25%;
    padding: 0px 10px;
    height: 70px;
    line-height: 70px;
    color: #fff;
  }
  .class-view li>div{
    width: 100%;
    height: 70px;
    text-align: center;
    cursor: pointer;
  }
  .class-view li:nth-of-type(1)>div{
    background: #fecd61;
  }
  .class-view li:nth-of-type(2)>div{
    background: #5671b3;
  }
  .class-view li:nth-of-type(3)>div{
    background: #a3d36c;
  }
  .class-view li:nth-of-type(4)>div{
    background: #e96a79;
  }
  .class-view  .class-icon{
    display: block;
    float: left;
    width: 70px;
    height: 70px;
    line-height: 70px;
    background: rgba(0,0,0,0.1);
    color: #fff;
    text-align: center;
    font-size: 40px;
  }
  .class-name {
    font-size: 20px;
  }
  .class-table{
    margin-top: 15px;
  }
  .class-day{
    height: 40px;
    line-height: 40px;
    padding-left: 125px;
    background: #2990fa;
    border-bottom: 1px solid #fff;
    position: relative;
  }
  .class-day li{
    float: left;
    color: #fff;
    text-align: center;
  }
  .class-info{
    height: auto;
    overflow: hidden;
  }
  .class-time{
    float: left;
    width: 125px;
  }
  .class-time .timer{
    height: 100px;
    margin-bottom: 1px;
  }
  .class-time .timer2{
    height: 50px;
    margin-bottom: 1px;
    background: #a5d1fe;
    text-align: center;
    line-height: 50px;
  }
  .class-time .timer>div{
    width: 50%;
    float: left;
    height: 100px;
    line-height: 20px;
    padding: 0px 20px;
    text-align: center;
  }
  .class-time .timer>div:first-child{
    background: #a5d1fe;
    padding-top: 32px;
  }
  .class-time .timer>div:last-child{
    background: #c0dfff;
  }
  .class-time .timer>div:last-child p{
    height: 50px;
    line-height: 50px;
  }
  .class-info .info{
    padding-left: 125px;
  }
  .class-info .info li{
    float: left;
    border-left: 1px solid #fff;
    background: #c0dfff;
    height: 252px;
  }
  .class-info .info .name{
    height: 50.5px;
    text-align: center;
    padding: 5px;
    line-height: 40px;
    overflow: hidden;
    cursor: pointer;
  }
  .class-info .info .name:nth-of-type(even){
    border-bottom: 1px solid #fff;
  }
</style>
